'use strict';

/**
 * @ngdoc overview
 * @name myappApp
 * @description
 * # myappApp
 *
 * Main module of the application.
 */
// 定义公共模块
angular.module('app.common.factory',[]);
angular.module('app.common.config',[]);
angular.module('app.common',['app.common.config', 'app.common.factory']);
var app = angular
    .module('myApp', [
        'ngAnimate',
        'ngCookies',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngTouch',
        'ui.router',
        'th.localize','th.logger','th.debounce','th.factory',
        'app.common',
        'app.demo',
    ])
    .config(['$routeProvider', '$stateProvider', '$urlRouterProvider',"configProvider","RestFulServiceFactoryProvider",
        function ($routeProvider, $stateProvider, $urlRouterProvider,configProvider, RestFulServiceFactoryProvider) {
            configProvider.configProps();
            RestFulServiceFactoryProvider.create(configProvider.RestfulApiConf);

            $urlRouterProvider.otherwise("/app/welcome");
            $stateProvider
                .state('app', {
                    url: '/app',
                    abstract: true
                })
                .state('app.welcome', {
                    url: '/welcome',
                    views:{
                        "@":{
                            templateUrl: "views/welcome.html"
                        }
                    }
                })
                .state('app.module', {
                    url: '/modules/{module}',
                    views:{
                        "@": {
                            templateUrl: function ($stateParams) {
                                return "views/templates/" + $stateParams.module + "/index.html";
                            }
                        }
                    }
                    /*resolve:{
                        module:['$stateParams', function ($stateParams) {
                            console.log($stateParams.module)
                            return $stateParams.module;
                        }]
                    }*/
                });
        }
    ])
    .run(["$rootScope", "$location", "logger","localize","config",
        function ($rootScope,$location,logger,localize,config) {
            /**
             * 本地语言环境配置
             */
            var currentLang = navigator.language;   //判断除IE外其他浏览器使用语言
            if (!currentLang) {//判断IE浏览器使用语言
                currentLang = navigator.browserLanguage;
            }
            logger.info("当前语言环境：" + currentLang);
            localize.configLang(config.langConf).setLang(currentLang);

            /**
             * 加载初始化数据
             */
            config.asyncInitialize();
            config.asyncData._all.then(function () {
                logger.info("所有数据加载完成")
            }, function () {
                logger.info("数据加载有误")
            }, function () {
                logger.log(arguments);
            })
        }])
    ;
